import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
import _regeneratorRuntime from "@babel/runtime/regenerator";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
var _excluded = ["tenantId"],
    _excluded2 = ["tenantId"],
    _excluded3 = ["tenantId"],
    _excluded4 = ["tenantId"];
import request from 'utils/request';
import { CPAAS_IAM, CPAAS_PLATFORM } from 'utils/config';
import { parseParameters, filterNullValueObject, isTenantRoleLevel } from 'utils/utils';
var organizationRoleLevel = isTenantRoleLevel();
/**
 *获取数据
 * @async
 * @function queryTenant
 * @param {String} params.tenantNum 组织编码
 * @param {String} params.tenantName 组织名称
 * @param {Number} [params.page = 0] - 数据页码
 * @param {Number} [params.size = 10] - 分页大小
 * @returns {Obejct}  fetch Promise
 */

export function queryTenant(_x) {
  return _queryTenant.apply(this, arguments);
}
/**
 * 获取树形菜单
 * @param {*} [params={}]
 */

function _queryTenant() {
  _queryTenant = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(params) {
    var param;
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            param = filterNullValueObject(parseParameters(params));
            return _context.abrupt("return", request("".concat(CPAAS_IAM, "/v1/tenants/having-custom-menu"), {
              method: 'GET',
              query: param
            }));

          case 2:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));
  return _queryTenant.apply(this, arguments);
}

export function queryMenuTree() {
  return _queryMenuTree.apply(this, arguments);
}

function _queryMenuTree() {
  _queryMenuTree = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
    var params,
        tenantId,
        _args2 = arguments;
    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            params = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : {};
            tenantId = params.tenantId;
            return _context2.abrupt("return", request("".concat(CPAAS_IAM, "/v1/tenant-menus/").concat(tenantId), {
              method: 'GET',
              query: params
            }));

          case 3:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  }));
  return _queryMenuTree.apply(this, arguments);
}

export function queryLabelList() {
  return _queryLabelList.apply(this, arguments);
}

function _queryLabelList() {
  _queryLabelList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
    var params,
        tenantId,
        others,
        _args3 = arguments;
    return _regeneratorRuntime.wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            params = _args3.length > 0 && _args3[0] !== undefined ? _args3[0] : {};
            tenantId = params.tenantId, others = _objectWithoutProperties(params, _excluded);
            return _context3.abrupt("return", request(organizationRoleLevel ? "".concat(CPAAS_IAM, "/v1/").concat(tenantId, "/labels/by-type") : "".concat(CPAAS_IAM, "/v1/labels/by-type"), {
              query: others,
              method: 'GET'
            }));

          case 3:
          case "end":
            return _context3.stop();
        }
      }
    }, _callee3);
  }));
  return _queryLabelList.apply(this, arguments);
}

export function queryMenuLabel(_x2) {
  return _queryMenuLabel.apply(this, arguments);
}
/**
 * 查询值集
 * @async
 * @function queryCode
 * @param {object} params - 查询条件
 * @param {!string} param.lovCode - 查询条件
 * @returns {object} fetch Promise
 */

function _queryMenuLabel() {
  _queryMenuLabel = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(params) {
    var tenantId, payload;
    return _regeneratorRuntime.wrap(function _callee4$(_context4) {
      while (1) {
        switch (_context4.prev = _context4.next) {
          case 0:
            tenantId = params.tenantId, payload = params.payload;
            return _context4.abrupt("return", request(organizationRoleLevel ? "".concat(CPAAS_IAM, "/v1/").concat(tenantId, "/label-rels/MENU/").concat(payload) : "".concat(CPAAS_IAM, "/v1/label-rels/MENU/").concat(payload), {
              method: 'GET'
            }));

          case 2:
          case "end":
            return _context4.stop();
        }
      }
    }, _callee4);
  }));
  return _queryMenuLabel.apply(this, arguments);
}

export function queryCode() {
  return _queryCode.apply(this, arguments);
}

function _queryCode() {
  _queryCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5() {
    var params,
        _args5 = arguments;
    return _regeneratorRuntime.wrap(function _callee5$(_context5) {
      while (1) {
        switch (_context5.prev = _context5.next) {
          case 0:
            params = _args5.length > 0 && _args5[0] !== undefined ? _args5[0] : {};
            return _context5.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/lovs/value"), {
              query: params
            }));

          case 2:
          case "end":
            return _context5.stop();
        }
      }
    }, _callee5);
  }));
  return _queryCode.apply(this, arguments);
}

export function queryDir() {
  return _queryDir.apply(this, arguments);
}

function _queryDir() {
  _queryDir = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6() {
    var params,
        _args6 = arguments;
    return _regeneratorRuntime.wrap(function _callee6$(_context6) {
      while (1) {
        switch (_context6.prev = _context6.next) {
          case 0:
            params = _args6.length > 0 && _args6[0] !== undefined ? _args6[0] : {};
            return _context6.abrupt("return", request("".concat(CPAAS_IAM, "/cpaas/v1/menus/dir"), {
              query: params
            }));

          case 2:
          case "end":
            return _context6.stop();
        }
      }
    }, _callee6);
  }));
  return _queryDir.apply(this, arguments);
}

export function queryPermissions() {
  return _queryPermissions.apply(this, arguments);
} // 查询权限集

function _queryPermissions() {
  _queryPermissions = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7() {
    var params,
        _args7 = arguments;
    return _regeneratorRuntime.wrap(function _callee7$(_context7) {
      while (1) {
        switch (_context7.prev = _context7.next) {
          case 0:
            params = _args7.length > 0 && _args7[0] !== undefined ? _args7[0] : {};
            return _context7.abrupt("return", request("".concat(CPAAS_IAM, "/cpaas/v1/permissions/self"), {
              query: params
            }));

          case 2:
          case "end":
            return _context7.stop();
        }
      }
    }, _callee7);
  }));
  return _queryPermissions.apply(this, arguments);
}

export function queryPermissionSetTree(_x3) {
  return _queryPermissionSetTree.apply(this, arguments);
} // 查询权限集下已分配的权限

function _queryPermissionSetTree() {
  _queryPermissionSetTree = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(menuId) {
    var params,
        _args8 = arguments;
    return _regeneratorRuntime.wrap(function _callee8$(_context8) {
      while (1) {
        switch (_context8.prev = _context8.next) {
          case 0:
            params = _args8.length > 1 && _args8[1] !== undefined ? _args8[1] : {};
            return _context8.abrupt("return", request("".concat(CPAAS_IAM, "/cpaas/v1/menus/").concat(menuId, "/permission-set"), {
              query: params
            }));

          case 2:
          case "end":
            return _context8.stop();
        }
      }
    }, _callee8);
  }));
  return _queryPermissionSetTree.apply(this, arguments);
}

export function queryPermissionsByMenuIdAll(_x4) {
  return _queryPermissionsByMenuIdAll.apply(this, arguments);
} // 查询权限集下已分配的Lov

function _queryPermissionsByMenuIdAll() {
  _queryPermissionsByMenuIdAll = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9(menuId) {
    var params,
        _args9 = arguments;
    return _regeneratorRuntime.wrap(function _callee9$(_context9) {
      while (1) {
        switch (_context9.prev = _context9.next) {
          case 0:
            params = _args9.length > 1 && _args9[1] !== undefined ? _args9[1] : {};
            return _context9.abrupt("return", request("".concat(CPAAS_IAM, "/cpaas/v1/menus/permission-set/").concat(menuId, "/permissions"), {
              query: params
            }));

          case 2:
          case "end":
            return _context9.stop();
        }
      }
    }, _callee9);
  }));
  return _queryPermissionsByMenuIdAll.apply(this, arguments);
}

export function queryLovsByMenuIdAll(_x5) {
  return _queryLovsByMenuIdAll.apply(this, arguments);
}

function _queryLovsByMenuIdAll() {
  _queryLovsByMenuIdAll = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10(menuId) {
    var params,
        _args10 = arguments;
    return _regeneratorRuntime.wrap(function _callee10$(_context10) {
      while (1) {
        switch (_context10.prev = _context10.next) {
          case 0:
            params = _args10.length > 1 && _args10[1] !== undefined ? _args10[1] : {};
            return _context10.abrupt("return", request("".concat(CPAAS_IAM, "/cpaas/v1/menus/permission-set/").concat(menuId, "/lovs"), {
              query: params
            }));

          case 2:
          case "end":
            return _context10.stop();
        }
      }
    }, _callee10);
  }));
  return _queryLovsByMenuIdAll.apply(this, arguments);
}

export function checkMenuDirExists() {
  return _checkMenuDirExists.apply(this, arguments);
} // 获取当前复制的节点及其子节点

function _checkMenuDirExists() {
  _checkMenuDirExists = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee11() {
    var params,
        _args11 = arguments;
    return _regeneratorRuntime.wrap(function _callee11$(_context11) {
      while (1) {
        switch (_context11.prev = _context11.next) {
          case 0:
            params = _args11.length > 0 && _args11[0] !== undefined ? _args11[0] : {};
            return _context11.abrupt("return", request("".concat(CPAAS_IAM, "/cpaas/v1/menus/check-duplicate"), {
              method: 'POST',
              body: params
            }));

          case 2:
          case "end":
            return _context11.stop();
        }
      }
    }, _callee11);
  }));
  return _checkMenuDirExists.apply(this, arguments);
}

export function queryCopyMenuList() {
  return _queryCopyMenuList.apply(this, arguments);
} // 复制并创建菜单

function _queryCopyMenuList() {
  _queryCopyMenuList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee12() {
    var params,
        _args12 = arguments;
    return _regeneratorRuntime.wrap(function _callee12$(_context12) {
      while (1) {
        switch (_context12.prev = _context12.next) {
          case 0:
            params = _args12.length > 0 && _args12[0] !== undefined ? _args12[0] : {};
            return _context12.abrupt("return", request("".concat(CPAAS_IAM, "/cpaas/v1/menus/copy"), {
              query: params
            }));

          case 2:
          case "end":
            return _context12.stop();
        }
      }
    }, _callee12);
  }));
  return _queryCopyMenuList.apply(this, arguments);
}

export function copyMenu(_x6) {
  return _copyMenu.apply(this, arguments);
} // 复制并创建菜单

function _copyMenu() {
  _copyMenu = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee13(payload) {
    return _regeneratorRuntime.wrap(function _callee13$(_context13) {
      while (1) {
        switch (_context13.prev = _context13.next) {
          case 0:
            return _context13.abrupt("return", request("".concat(CPAAS_IAM, "/v1/tenant-menus/copy"), {
              method: 'POST',
              body: payload
            }));

          case 1:
          case "end":
            return _context13.stop();
        }
      }
    }, _callee13);
  }));
  return _copyMenu.apply(this, arguments);
}

export function createMenu(_x7) {
  return _createMenu.apply(this, arguments);
} // 复制并创建菜单

function _createMenu() {
  _createMenu = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee14(payload) {
    var tenantId, menu;
    return _regeneratorRuntime.wrap(function _callee14$(_context14) {
      while (1) {
        switch (_context14.prev = _context14.next) {
          case 0:
            tenantId = payload.tenantId, menu = payload.menu;
            return _context14.abrupt("return", request("".concat(CPAAS_IAM, "/v1/tenant-menus/add?tenantId=").concat(tenantId), {
              method: 'POST',
              body: menu
            }));

          case 2:
          case "end":
            return _context14.stop();
        }
      }
    }, _callee14);
  }));
  return _createMenu.apply(this, arguments);
}

export function saveMenu(_x8) {
  return _saveMenu.apply(this, arguments);
}

function _saveMenu() {
  _saveMenu = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee15(payload) {
    var tenantId, menu;
    return _regeneratorRuntime.wrap(function _callee15$(_context15) {
      while (1) {
        switch (_context15.prev = _context15.next) {
          case 0:
            tenantId = payload.tenantId, menu = payload.menu;
            return _context15.abrupt("return", request("".concat(CPAAS_IAM, "/v1/tenant-menus?tenantId=").concat(tenantId), {
              method: 'PUT',
              body: menu
            }));

          case 2:
          case "end":
            return _context15.stop();
        }
      }
    }, _callee15);
  }));
  return _saveMenu.apply(this, arguments);
}

export function enable(_x9) {
  return _enable.apply(this, arguments);
}

function _enable() {
  _enable = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee16(params) {
    var tenantId, rest;
    return _regeneratorRuntime.wrap(function _callee16$(_context16) {
      while (1) {
        switch (_context16.prev = _context16.next) {
          case 0:
            tenantId = params.tenantId, rest = _objectWithoutProperties(params, _excluded2);
            return _context16.abrupt("return", request("".concat(CPAAS_IAM, "/v1/tenant-menus/enable?tenantId=").concat(tenantId), {
              method: 'PUT',
              body: rest
            }));

          case 2:
          case "end":
            return _context16.stop();
        }
      }
    }, _callee16);
  }));
  return _enable.apply(this, arguments);
}

export function disable(_x10) {
  return _disable.apply(this, arguments);
} // 查询权限集下可分配的所有权限

function _disable() {
  _disable = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee17(params) {
    var tenantId, rest;
    return _regeneratorRuntime.wrap(function _callee17$(_context17) {
      while (1) {
        switch (_context17.prev = _context17.next) {
          case 0:
            tenantId = params.tenantId, rest = _objectWithoutProperties(params, _excluded3);
            return _context17.abrupt("return", request("".concat(CPAAS_IAM, "/v1/tenant-menus/disable?tenantId=").concat(tenantId), {
              method: 'PUT',
              body: rest
            }));

          case 2:
          case "end":
            return _context17.stop();
        }
      }
    }, _callee17);
  }));
  return _disable.apply(this, arguments);
}

export function queryPermissionsByMenuId(_x11) {
  return _queryPermissionsByMenuId.apply(this, arguments);
} // 查询权限集下可分配的所有lov

function _queryPermissionsByMenuId() {
  _queryPermissionsByMenuId = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee18(menuId) {
    var params,
        tenantId,
        rest,
        _args18 = arguments;
    return _regeneratorRuntime.wrap(function _callee18$(_context18) {
      while (1) {
        switch (_context18.prev = _context18.next) {
          case 0:
            params = _args18.length > 1 && _args18[1] !== undefined ? _args18[1] : {};
            tenantId = params.tenantId, rest = _objectWithoutProperties(params, _excluded4);
            return _context18.abrupt("return", request("".concat(CPAAS_IAM, "/v1/tenant-menus/").concat(menuId, "/assignable-permissions?tenantId=").concat(tenantId), {
              query: rest
            }));

          case 3:
          case "end":
            return _context18.stop();
        }
      }
    }, _callee18);
  }));
  return _queryPermissionsByMenuId.apply(this, arguments);
}

export function queryLovByMenuId(_x12) {
  return _queryLovByMenuId.apply(this, arguments);
}

function _queryLovByMenuId() {
  _queryLovByMenuId = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee19(menuId) {
    var params,
        _args19 = arguments;
    return _regeneratorRuntime.wrap(function _callee19$(_context19) {
      while (1) {
        switch (_context19.prev = _context19.next) {
          case 0:
            params = _args19.length > 1 && _args19[1] !== undefined ? _args19[1] : {};
            return _context19.abrupt("return", request("".concat(CPAAS_IAM, "/v1/tenant-menus/").concat(menuId, "/assignable-lovs"), {
              query: params
            }));

          case 2:
          case "end":
            return _context19.stop();
        }
      }
    }, _callee19);
  }));
  return _queryLovByMenuId.apply(this, arguments);
}